package xyz.poke.business.tool.utils;

import org.apache.commons.lang3.BooleanUtils;
import xyz.poke.business.tool.exception.BusinessException;

import java.util.Objects;

/**
 * @author 迫壳
 * @date 2024/3/9 21:33
 * 校验工具类
 */
public class CheckerUtils {

    public static void notNull(Object o, String errorMessage) {
        if (Objects.isNull(o)) {
            throw new BusinessException(errorMessage);
        }
    }

    public static void isNull(Object o, String errorMessage) {
        if (Objects.nonNull(o)) {
            throw new BusinessException(errorMessage);
        }
    }

    public static void isTrue(Boolean flag, String errorMessage) {
        if (BooleanUtils.isNotTrue(flag)) {
            throw new BusinessException(errorMessage);
        }
    }

    public static void isNotTrue(Boolean flag, String errorMessage) {
        if (BooleanUtils.isTrue(flag)) {
            throw new BusinessException(errorMessage);
        }
    }

}
